package exception;

/**
 *
 */
public class TryCatchDemo {
    public static void main(String[] args) {
        System.out.println("程序开始了");
        try {
            //String str=null;
            //String str="";
            String str="a";

            System.out.println(str.length());

            System.out.println(str.charAt(0));

            System.out.println(Integer.parseInt(str));

        }/*catch (NullPointerException e){
            System.out.println("出现了空指针异常!");
        }
        catch (StringIndexOutOfBoundsException e){
            System.out.println("越界异常!");}*/
        catch (NullPointerException | StringIndexOutOfBoundsException e){
            System.out.println("出现两种异常解决办法!!");
        }catch (Exception e){
            System.out.println("出错了!!!");
        }
        //当JVM执行程序遇到一个异常时就会实例化该异常并将其输出

        System.out.println("程序结束了");
    }
}
